﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;

namespace DAL
{
    public class D_Admin
    {
        public bool Login(Admin m_admin)
        {
            var log = Sugar_helper.Db.Queryable<Admin>().Where(a=>a.admin_uname==m_admin.admin_uname && a.pwd==m_admin.pwd).ToList();
            if(log.Count > 0) 
            { 
                log_info.admin.admin_uname = m_admin.admin_uname;
                var sys_config = Sugar_helper.Db.Queryable<Sys_config>().ToList();

                if (sys_config.Count > 0)
                {
                    log_info.Sys_Config.tearch_choice = sys_config[0].tearch_choice;
                    log_info.Sys_Config.group_choice = sys_config[0].group_choice;
                }

                return true; 
            }

            return false;
        }

        public bool save_List(List<Admin> list)
        {
            var res = Sugar_helper.Db.Storageable(list).WhereColumns(admin => admin.admin_uname).ExecuteCommand();
            return res == list.Count ? true : false;
        }

        public List<Admin> GetList()
        {
            return Sugar_helper.Db.Queryable<Admin>().ToList();
        }

        public bool Del(List<Admin> list)
        {
            var res = Sugar_helper.Db.Deleteable(list).ExecuteCommand();
            return res == list.Count ? true : false;
        }
    }
}
